import { put, takeEvery } from 'redux-saga/effects'
import { loadProducts, saveProducts } from '../actions/product.action'
import axios from 'axios'
function* loadProducts_fn() {
  // 加载 products
  const { data } = yield axios.get('http://localhost:3005/goods')
  // 使用put触发action 保存products
  yield put(saveProducts(data))
}

export default function* productSaga() {
  // takeEvery 需要拦截到的 action 并调用对该 action 的处理函数
  yield takeEvery(loadProducts, loadProducts_fn)
}
